package com.yswy.backstage.redislistener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Service;

/**
 * Description: Redis超时监听器
 * User: liw
 * Date: 2023-05-20
 */
@Service
public class RedisExpirationListener extends KeyExpirationEventMessageListener {


    private static Logger log = LoggerFactory.getLogger(RedisExpirationListener.class);

    public RedisExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        //获取过期的key
        String expireKey = message.toString();
        log.debug("失效+key is:"+ expireKey);
        System.out.println(expireKey);
        //这里还可以根据key的自定义前缀来判断执行哪个条件
        //......
    }
}
